package g6.UddiRegistration;

import java.rmi.RemoteException;
import java.util.List;

import org.uddi.api_v3.BusinessDetail;
import org.uddi.api_v3.BusinessEntity;
import org.uddi.api_v3.BusinessList;
import org.uddi.api_v3.FindBusiness;
import org.uddi.api_v3.FindService;
import org.uddi.api_v3.GetBusinessDetail;
import org.uddi.api_v3.Name;
import org.uddi.api_v3.ServiceList;
import org.uddi.v3_service.DispositionReportFaultMessage;
import org.uddi.v3_service.UDDIInquiryPortType;

import SC12Project.Milestone2.SearchEngine.ServiceInfo;

public class JuddiSearcher {
	private UDDIInquiryPortType myInquiryPortType; 
	
	public JuddiSearcher(UDDIInquiryPortType inquiryPortType) {
		this.myInquiryPortType = inquiryPortType;
	}
	
	public BusinessList findBusiness(String searchPattern) throws DispositionReportFaultMessage, RemoteException  
    {  		
        FindBusiness fb = new FindBusiness();  
        Name findName = new Name();  
        findName.setValue(searchPattern);  
        fb.getName().add(findName);  
        BusinessList list = this.myInquiryPortType.findBusiness(fb);
		return list;
    }  
	
	public BusinessEntity getBusinessEntity(String key) throws DispositionReportFaultMessage, RemoteException{
		GetBusinessDetail getBusinessDetail = new GetBusinessDetail();
		getBusinessDetail.getBusinessKey().add(key);		
		BusinessDetail businessDetail = myInquiryPortType.getBusinessDetail(getBusinessDetail);
		List<BusinessEntity> list = businessDetail.getBusinessEntity();
		if (list.size() > 0)
			return list.get(0);
		
		return null;
	}
	
	/*public ServiceList getServices(String keyword) throws DispositionReportFaultMessage, RemoteException
	{		
		FindService fs = new FindService();
		Name findName = new Name();
		findName.setValue(keyword);
		fs.getName().add(findName);
		ServiceList list = myInquiryPortType.findService(fs);
		org.uddi.api_v3.ServiceInfo si = list.getServiceInfos().getServiceInfo().get(0);
		si.getBusinessKey();
		return list;
	}*/
}
